home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’90 / Busy Box / Sources / radar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-14  |  1.1 KB  |  60 lines  |  [TEXT/KAHL]

  1. /* file: radar.c    
  2.     sweeping line algorithm
  3.     By MGD
  4. */
  5.  
  6. #include "busybox.h"
  7. #include <math.h>
  8. #define abs(x)    ((x <= 0) ? (-x) : (x))
  9. #define numSpots 48
  10.  
  11. static Rect    ourRect;
  12. static int16 numThru;
  13. static width, height;
  14.  
  15. static Point circle[numSpots];
  16. static int16 radius;
  17. static int16 lasti;
  18. static Point centre;
  19.  
  20.  
  21. void InitRadarObj(Rect *drawArea, int16 ID)    {
  22.     /* You can put various stuffages here - i.e. load string resources, init a brick
  23.         picture, oop ack.    */
  24.     int16    i;
  25.     double sinner, cosinner, thetaStep, theta;
  26.     
  27.     ourRect = *drawArea;
  28.     width = ourRect.right;
  29.     height = ourRect.bottom;
  30.     
  31.     radius = width / 2;
  32.     centre.h = radius;
  33.     centre.v = radius;
  34. /*    SetRect(&ourRect,0, 0, 500, 500);    */
  35.     
  36.     thetaStep = (2*3.14159) / numSpots;
  37.     theta = 0;
  38.     for (i = 0; i < numSpots; i++)    {
  39.         circle[i].h = radius * cos(theta) + radius;
  40.         circle[i].v = radius * sin(theta) + radius;
  41.         theta += thetaStep;
  42.     }
  43.     lasti = 0;
  44. }    /* InitRadarObj    */
  45.  
  46.  
  47.  
  48. void DrawRadarObj(int16 ID)    {
  49.  
  50.     FillOval(&ourRect,black);
  51.     MoveTo(centre.h, centre.v);
  52.     PenPat(white);
  53.     LineTo(circle[lasti].h, circle[lasti].v);
  54.     lasti = (++lasti % numSpots);
  55.     PenPat(black);
  56. }    /* DrawRadarObj    */
  57.  
  58.  
  59.  
  60.